#!/bin/bash

function log() {
   printf "%(%Y-%m-%d %H:%M:%S %Z)T rc.local: "
   echo $@
}

log "Hello, this is rc.local. CONTAINER_NAME is $CONTAINER_NAME, and DEPLOY_ENV is $DEPLOY_ENV"

if [ "${CONTAINER_NAME}" = "listenbrainz-web-${DEPLOY_ENV}" ]
then
    log Enabling web
    rm -f /etc/service/uwsgi/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-timescale-writer-${DEPLOY_ENV}" ]
then
    log Enabling timescale writer
    rm -f /etc/service/timescale_writer/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-background-tasks-${DEPLOY_ENV}" ]
then
    log Enabling background tasks
    rm -f /etc/service/background_tasks/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-api-compat-${DEPLOY_ENV}" ]
then
    log Enabling api compat
    rm -f /etc/service/api_compat/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-websockets-${DEPLOY_ENV}" ]
then
    log Enabling websockets
    rm -f /etc/service/websockets/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-spotify-reader-${DEPLOY_ENV}" ]
then
    log Enabling spotify reader
    rm -f /etc/service/spotify_reader/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-lastfm-reader-${DEPLOY_ENV}" ]
then
    log Enabling last.fm importer
    rm -f /etc/service/lastfm_importer/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-librefm-reader-${DEPLOY_ENV}" ]
then
    log Enabling libre.fm importer
    rm -f /etc/service/librefm_importer/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-spark-reader-${DEPLOY_ENV}" ]
then
    log Enabling spark reader
    rm -f /etc/service/spark_reader/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-labs-api-${DEPLOY_ENV}" ]
then
    log Enabling api labs
    rm -f /etc/service/labs_api/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-cron-prod" ]
then
    log Enabling cron
    rm -f /etc/service/cron/down
    rm -f /etc/service/cron-config/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-mbid-mapping-writer-${DEPLOY_ENV}" ]
then
    rm -f /etc/service/mbid_mapping_writer/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-internetarchive-metadata-cache-${DEPLOY_ENV}" ]
then
    log Enabling internet archive metadata cache
    rm -f /etc/service/internetarchive_metadata_cache/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-spotify-metadata-cache-${DEPLOY_ENV}" ]
then
    rm -f /etc/service/spotify_metadata_cache/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-apple-metadata-cache-${DEPLOY_ENV}" ]
then
    rm -f /etc/service/apple_metadata_cache/down
fi

if [ "${CONTAINER_NAME}" = "listenbrainz-soundcloud-metadata-cache-${DEPLOY_ENV}" ]
then
    rm -f /etc/service/soundcloud_metadata_cache/down
fi

